from sanic import Sanic
from sanic.response import json
import asyncio
import time
from kfkmessage.message import Message


app = Sanic()


@app.route('/')
async def index(request):
    return json({'hello': 'world'})


@app.middleware('response')
async def print_on_response(request, response):
    q = request.args.get('q')
    a = {
        'a': 1
    }
    await app.producer.send("testaa", a)
    # print(test(1))


@app.listener('before_server_start')
async def server_init(app, loop):
    app.producer = Message(loop, bootstrap_servers='115.29.76.68:9092').producer_message()
    # await app.producer.start()


if __name__ == '__main__':
    app.run(host='0.0.0.0', port='8000')
